/*
 * CombinedAnalyzer.java
 *
 * Created on 14 September 2006, 8:55
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package fasea.index;

import fasea.constants.Constants;
import java.io.Reader;
import java.util.HashMap;
import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.de.GermanAnalyzer;
import org.apache.lucene.analysis.en.EnglishAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;

/**
 *
 * @author gvasil
 * @author lars-wolfram
 */
public final class CombinedAnalyzer extends Analyzer {

    Analyzer analyzer;
    
    private CombinedAnalyzer() {
    }

    public static CombinedAnalyzer getInstance() {
        CombinedAnalyzer ret = new CombinedAnalyzer();
        Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>();
        analyzerPerField.put("germanContent", new GermanAnalyzer(Constants.getLuceneVersion()));
        analyzerPerField.put("englishContent", new EnglishAnalyzer(Constants.getLuceneVersion()));
        ret.analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Constants.getLuceneVersion()), analyzerPerField);
        return ret;
    }

    public TokenStream tokenStream(String fieldName, Reader reader) {
        TokenStream tokens = analyzer.tokenStream(fieldName, reader);
        return tokens;
    }
}
